java我需要帮助在for循环中使用大写这个词,这个词不是用eclipse编写的,而是从txt文件导入的
import java.util.*;
import java.io.*;
public class Cascader {
public static void main(String args[]) throws IOException {
Scanner inputfile = new Scanner(new File("name.txt"));
String name = inputfile.nextLine();
System.out.println("Reading the name...");
for(int i = 0; i < name.length(); i++) {
System.out.println(name.charAt(i));
}
inputfile.close();
}
}
# 1 楼答案
回答您的问题:您可能没有“保存”新字符串。
toUpperCase()
方法返回一个新字符串,其中每个字符都已改为大写